﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace IPIdee.MapServices.Client.Entities.Coordinates
{
    /// <summary>
    /// Represents a coordinate of a MapSpot in the relative tile coordinates system
    /// </summary>
    public class RelMapSpotCoordinate
    {
        public RelMapSpotCoordinate(int tileX, int tileY, int relativeMapSpotX, int relativeMapSpotY, int zoom)
        {
            this.TileX = tileX;
            this.TileY = tileY;
            this.RelativeMapSpotX = relativeMapSpotX;
            this.RelativeMapSpotY = relativeMapSpotY;
            this.Zoom = zoom;
        }

        public int TileX
        {
            get;
            set;
        }

        public int TileY
        {
            get;
            set;
        }

        public int RelativeMapSpotX
        {
            get;
            set;
        }

        public int RelativeMapSpotY
        {
            get;
            set;
        }

        public int Zoom
        {
            get;
            set;
        }

        public static implicit operator AbsMapSpotCoordinate(RelMapSpotCoordinate sourceCoordinate)
        {
            var absX = CoordinateConvertor.GetAbsoluteXByRelativeCoordinateElements(sourceCoordinate.TileX, sourceCoordinate.RelativeMapSpotX);
            var absY = CoordinateConvertor.GetAbsoluteYByRelativeCoordinateElements(sourceCoordinate.TileY, sourceCoordinate.RelativeMapSpotY);
            var result = new AbsMapSpotCoordinate(absX, absY, sourceCoordinate.Zoom);

            return result;
        }
    }
}
